//
//  DetailsTableViewCell.m
//  A段项目
//
//  Created by 官琛 on 15-6-20.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "DetailsTableViewCell.h"

@implementation DetailsTableViewCell



-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        if (WIDTH == 320 && HEIGHT == 568) {
            [self creatTable5];
        }
        if (WIDTH == 414 && HEIGHT == 736) {
            [self creatTablePlus];
        }
        if (WIDTH == 375 && HEIGHT == 667){
            [self creatTable6];
        }

    }
    return self;

}

-(void)creatTable5
{
    //图片
    self.StarIamge = [[UIImageView alloc]initWithFrame:CGRectMake(30, 10, 90, 130)];
    [self.contentView addSubview:self.StarIamge];
    [_StarIamge release];
    //人物详情
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:button];
    //排名
    self.numLabel = [[UILabel alloc]initWithFrame:CGRectMake(5, 10, 20,20 )];
    [self.contentView addSubview:self.numLabel];
    self.numLabel.textAlignment = NSTextAlignmentCenter;
    self.numLabel.layer.masksToBounds = YES;
    self.numLabel.layer.cornerRadius = 10;
    
    [_nameLabel release];
    //姓名
    self.nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(130, self.StarIamge.frame.origin.y, 130, 30)];
    self.nameLabel.font = [UIFont boldSystemFontOfSize:18];
    [self.contentView addSubview:self.nameLabel];
    [_nameLabel release];
    //评分
    self.gradeLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.nameLabel.frame.origin.x + self.nameLabel.frame.size.width-20, self.nameLabel.frame.origin.y, 80, 30)];
    [self.contentView addSubview:self.gradeLabel];
    [_gradeLabel release];
    //英文名
    self.enLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.nameLabel.frame.origin.x, self.nameLabel.frame.origin.y+self.nameLabel.frame.size.height, 150, 20)];
    self.enLabel.font = [UIFont systemFontOfSize:12];
    self.enLabel.textColor = [UIColor lightGrayColor];
    [self.contentView addSubview:self.enLabel];
    [_enLabel release];
    //性别
    self.sexLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.enLabel.frame.origin.x, self.enLabel.frame.origin.y+self.enLabel.frame.size.height +5, 10, 20)];
    self.sexLabel.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:self.sexLabel];
    [_sexLabel release];
    //生日
    self.birthbirthDay = [[UILabel alloc]initWithFrame:CGRectMake(self.sexLabel.frame.origin.x+15, self.sexLabel.frame.origin.y, 55, 20)];
    self.birthbirthDay.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:self.birthbirthDay];
    [_birthbirthDay release];
    //出生地
    self.birthLocation = [[UILabel alloc]initWithFrame:CGRectMake(self.birthbirthDay.frame.origin.x+self.birthbirthDay.frame.size.width, self.birthbirthDay.frame.origin.y, 120, 20)];
    self.birthLocation.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:self.birthLocation];
    [_birthLocation release];
    //简介
    self.subLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.sexLabel.frame.origin.x, self.sexLabel.frame.origin.y+15, 180, 60)];
    self.subLabel.numberOfLines = 0;
    self.subLabel.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:self.subLabel];
    [_subLabel release];
    
}


-(void)creatTable6
{
    //图片
    self.StarIamge = [[UIImageView alloc]initWithFrame:CGRectMake(30, 10, 90, 130)];
    [self.contentView addSubview:self.StarIamge];
    [_StarIamge release];
    //人物详情
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:button];
    //排名
    self.numLabel = [[UILabel alloc]initWithFrame:CGRectMake(5, 10, 20,20 )];
    [self.contentView addSubview:self.numLabel];
    self.numLabel.textAlignment = NSTextAlignmentCenter;
    self.numLabel.layer.masksToBounds = YES;
    self.numLabel.layer.cornerRadius = 10;

    [_nameLabel release];
    //姓名
    self.nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(130, self.StarIamge.frame.origin.y, 170, 30)];
    self.nameLabel.font = [UIFont boldSystemFontOfSize:18];
    [self.contentView addSubview:self.nameLabel];
    [_nameLabel release];
    //评分
    self.gradeLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.nameLabel.frame.origin.x + self.nameLabel.frame.size.width-10, self.nameLabel.frame.origin.y, 80, 30)];
    [self.contentView addSubview:self.gradeLabel];
    [_gradeLabel release];
    //英文名
    self.enLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.nameLabel.frame.origin.x, self.nameLabel.frame.origin.y+self.nameLabel.frame.size.height, 150, 20)];
    self.enLabel.font = [UIFont systemFontOfSize:12];
    self.enLabel.textColor = [UIColor lightGrayColor];
    [self.contentView addSubview:self.enLabel];
    [_enLabel release];
    //性别
    self.sexLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.enLabel.frame.origin.x, self.enLabel.frame.origin.y+self.enLabel.frame.size.height +5, 10, 20)];
    self.sexLabel.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:self.sexLabel];
    [_sexLabel release];
    //生日
    self.birthbirthDay = [[UILabel alloc]initWithFrame:CGRectMake(self.sexLabel.frame.origin.x+15, self.sexLabel.frame.origin.y, 55, 20)];
    self.birthbirthDay.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:self.birthbirthDay];
    [_birthbirthDay release];
    //出生地
    self.birthLocation = [[UILabel alloc]initWithFrame:CGRectMake(self.birthbirthDay.frame.origin.x+self.birthbirthDay.frame.size.width, self.birthbirthDay.frame.origin.y, 120, 20)];
    self.birthLocation.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:self.birthLocation];
    [_birthLocation release];
    //简介
    self.subLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.sexLabel.frame.origin.x, self.sexLabel.frame.origin.y+15, 220, 60)];
    self.subLabel.numberOfLines = 0;
    self.subLabel.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:self.subLabel];
    [_subLabel release];

}

-(void)creatTablePlus
{
    //图片
    self.StarIamge = [[UIImageView alloc]initWithFrame:CGRectMake(30, 10, 100, 140)];
    [self.contentView addSubview:self.StarIamge];
    [_StarIamge release];
    //人物详情
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:button];
    //排名
    self.numLabel = [[UILabel alloc]initWithFrame:CGRectMake(5, 10, 20,20 )];
    [self.contentView addSubview:self.numLabel];
    self.numLabel.textAlignment = NSTextAlignmentCenter;
    self.numLabel.layer.masksToBounds = YES;
    self.numLabel.layer.cornerRadius = 10;
    
    [_nameLabel release];
    //姓名
    self.nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(140, self.StarIamge.frame.origin.y, 170, 30)];
    self.nameLabel.font = [UIFont boldSystemFontOfSize:18];
    [self.contentView addSubview:self.nameLabel];
    [_nameLabel release];
    //评分
    self.gradeLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.nameLabel.frame.origin.x + self.nameLabel.frame.size.width+20, self.nameLabel.frame.origin.y, 80, 30)];
    [self.contentView addSubview:self.gradeLabel];
    [_gradeLabel release];
    //英文名
    self.enLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.nameLabel.frame.origin.x, self.nameLabel.frame.origin.y+self.nameLabel.frame.size.height, 150, 20)];
    self.enLabel.font = [UIFont systemFontOfSize:13];
    self.enLabel.textColor = [UIColor lightGrayColor];
    [self.contentView addSubview:self.enLabel];
    [_enLabel release];
    //性别
    self.sexLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.enLabel.frame.origin.x, self.enLabel.frame.origin.y+self.enLabel.frame.size.height +5, 15, 20)];
    self.sexLabel.font = [UIFont systemFontOfSize:13];
    [self.contentView addSubview:self.sexLabel];
    [_sexLabel release];
    //生日
    self.birthbirthDay = [[UILabel alloc]initWithFrame:CGRectMake(self.sexLabel.frame.origin.x+15, self.sexLabel.frame.origin.y, 65, 20)];
    self.birthbirthDay.font = [UIFont systemFontOfSize:13];
    [self.contentView addSubview:self.birthbirthDay];
    [_birthbirthDay release];
    //出生地
    self.birthLocation = [[UILabel alloc]initWithFrame:CGRectMake(self.birthbirthDay.frame.origin.x+self.birthbirthDay.frame.size.width, self.birthbirthDay.frame.origin.y, 120, 20)];
    self.birthLocation.font = [UIFont systemFontOfSize:13];
    [self.contentView addSubview:self.birthLocation];
    [_birthLocation release];
    //简介
    self.subLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.sexLabel.frame.origin.x, self.sexLabel.frame.origin.y+15, 250, 70)];
    self.subLabel.numberOfLines = 0;
    self.subLabel.font = [UIFont systemFontOfSize:13];
    [self.contentView addSubview:self.subLabel];
    [_subLabel release];
    
}


-(void)setCemCell:(Cemera *)cemCell
{
    if (_cemCell != cemCell) {
        [_cemCell release];
        _cemCell = [cemCell retain];
    }
    NSURL *url = [NSURL URLWithString:cemCell.posterUrl];
    [self.StarIamge sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"111111.png"]];
    self.subLabel.text = cemCell.summary;
    self.numLabel.text = [NSString stringWithFormat:@"%ld",cemCell.rankNum];
    if (cemCell.rankNum == 1) {
        [self.numLabel setBackgroundColor:[UIColor orangeColor]];
    }else if (cemCell.rankNum == 2) {
        [self.numLabel setBackgroundColor:[UIColor greenColor]];
    }else if(cemCell.rankNum == 3){
        [self.numLabel setBackgroundColor:[UIColor cyanColor]];
    }else{
        [self.numLabel setBackgroundColor:[UIColor lightGrayColor]];
    }
    self.nameLabel.text = cemCell.nameCn;
    
    self.enLabel.text = cemCell.nameEn;
    self.sexLabel.text = cemCell.sex;
    self.birthLocation.text = [NSString stringWithFormat:@"(%@)",cemCell.birthLocation];
    self.birthbirthDay.text = cemCell.birthDay;
    self.perId = cemCell.idd;
    
    if (cemCell.rating >= 0) {
        
        self.gradeLabel.text = [NSString stringWithFormat:@"评分:%.1f",(float)cemCell.rating];
       
    }
    
    
    
   
    
    
    
    
   
}

-(void)buttonAction:(UIButton *)button
{
    
    [self.myDelegate bringPersonId];
}





- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
